package com.insigma.business.qrcode.soldier._bff.impl;

import cn.hutool.core.bean.BeanUtil;
import com.insigma.business.qrcode.common.template.BasePagingResponse;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.soldier.dto.gov.BaseProviderImpl;
import com.insigma.business.qrcode.common.template.area.ScenarioCodeEnum;
import com.insigma.business.qrcode.common.template.area.ServiceCallback;
import com.insigma.business.qrcode.soldier.request.PlacementWordConfigSearchRequest;
import com.insigma.business.qrcode.soldier._bff.PlacementWordConfigBFFProvider;
import com.insigma.business.qrcode.soldier._consumer.PlacementWordConfigConsumer;
import com.insigma.business.qrcode.soldier.service.impl.PlacementWordConfigDTO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PlacementWordConfigBFFProviderImpl extends BaseProviderImpl implements PlacementWordConfigBFFProvider {

    @Resource
    PlacementWordConfigConsumer placementWordConfigConsumer;

    @Override
    public BasePagingResponse<List<PlacementWordConfigDTO>> searchPlacementWordConfig(PlacementWordConfigSearchRequest searchRequest) {
        final BasePagingResponse<List<PlacementWordConfigDTO>> basePagingResponse = new BasePagingResponse<>();
        serviceTemplate.execute(basePagingResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(searchRequest, "查询分页PlacementWordConfig的请求参数不能为空");
            }

            @Override
            public void executeService() {
                searchRequest.setSortKeyValueJoint("seqNo_desc");
                BasePagingResponse<List<PlacementWordConfigDTO>> listBasePagingResponse = placementWordConfigConsumer.searchPlacementWordConfig(searchRequest);
                BeanUtil.copyProperties(listBasePagingResponse, basePagingResponse);
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.PLACEMENT_WORD_CONFIG_SEARCH;
            }
        });

        return basePagingResponse;
    }
}
